package netty.session;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.netty.channel.Channel;

public class NettySession {
    private String sessionId; // 可以是设备标识符，比如SIM卡号
    @JsonIgnore
    private Channel channel;
    private String serverId;
    private int sequenceNo = 0; // 消息流水号 word(16) 按发送顺序从 0 开始循环累加

    public NettySession() { }

    public NettySession(String sessionId, Channel channel, String serverId) {
        this.sessionId = sessionId;
        this.channel = channel;
        this.serverId = serverId;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Channel getChannel() {
        return channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }

    public synchronized int nextSequenceNo() {
        if (sequenceNo >= 0xffff) {
            sequenceNo = 0;
        }
        return ++sequenceNo;
    }
}
